import request from '@/utils/request'
import * as mock from './mock/message'

const isMock = import.meta.env.VITE_API_MOCK === 'true'

/**
 * 发送邮件(未登录状态)
 * @param {Object} data 邮件数据
 * @returns {Promise}
 */
export function sendEmail(data) {
  if (isMock) {
    return Promise.resolve(mock.sendEmail(data))
  }
  return request({
    url: '/:appType/email/send',
    method: 'post',
    data
  })
}

/**
 * 发送邮件(登录状态)
 * @param {Object} data 邮件数据
 * @returns {Promise}
 */
export function sendEmailWithToken(data) {
  if (isMock) {
    return Promise.resolve(mock.sendEmailWithToken(data))
  }
  return request({
    url: '/:appType/email/token/send',
    method: 'post',
    data
  })
}

/**
 * 验证邮件验证码
 * @param {Object} data 验证数据
 * @returns {Promise}
 */
export function checkEmail(data) {
  if (isMock) {
    return Promise.resolve(mock.checkEmail(data))
  }
  return request({
    url: '/:appType/email/check',
    method: 'post',
    data
  })
}

/**
 * 发送短信(未登录状态)
 * @param {Object} data 短信数据
 * @returns {Promise}
 */
export function sendSms(data) {
  if (isMock) {
    return Promise.resolve(mock.sendSms(data))
  }
  return request({
    url: '/:appType/msg/send',
    method: 'post',
    data
  })
}

/**
 * 发送短信(登录状态)
 * @param {Object} data 短信数据
 * @returns {Promise}
 */
export function sendSmsWithToken(data) {
  if (isMock) {
    return Promise.resolve(mock.sendSmsWithToken(data))
  }
  return request({
    url: '/:appType/msg/token/send',
    method: 'post',
    data
  })
}

/**
 * 验证短信验证码
 * @param {Object} data 验证数据
 * @returns {Promise}
 */
export function checkSms(data) {
  if (isMock) {
    return Promise.resolve(mock.checkSms(data))
  }
  return request({
    url: '/:appType/msg/check',
    method: 'post',
    data
  })
}